import axios from "axios";

//一个axios实例
const instance = axios.create( {
  baseURL: "https://www.ahsj.link/nebula-api",
  timeout: 5000
})

//l拦截器: 拦截请求
instance.interceptors.request.use(config => {
  //判断本地是否有token, 有: 把token放入请求头中
  let token = localStorage.getItem("token");
  if (token) {
    config.headers["x-auth-token"] = token;
  }

  return config;
}, error => {
  return Promise.reject(error);
});
//拦截器: 拦截响应
instance.interceptors.response.use(res => {
  // console.log("拦截响应", res);
  return res.data;
}, error => {
  return Promise.reject(error);
});

export default instance;